package happens_before;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author juntao zhang
 */
public class JoinRule {

  public static void main(String[] args) throws InterruptedException {
    final List<String> list = new ArrayList<>();
    list.add("0");  //0 (0 happens-before 1) Thread start rule
    Thread t = new Thread(new Runnable() {
      @Override
      public void run() {
        try {
          Thread.sleep(1000);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
        System.out.println("in thread");//1
        list.add("1");
      }
    });
    t.start();
    t.join();
    list.add("2");  //2 (1 happens before 2) Thread termination rule
    System.out.println(list);
  }
}
